home *** CD-ROM | disk | FTP | other *** search
- /* ProjectDrag.c: Main application code for all applets in ProjectDrag
- * Mutated from DropShell.c.
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
-
- #ifndef __MWERKS__
- #include <Desk.h>
- #include <Dialogs.h>
- #include <DiskInit.h>
- #include <Errors.h>
- #include <Files.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <StandardFile.h>
- #include <TextEdit.h>
- #include <Types.h>
- #include <Windows.h>
- #endif
-
- #include "DSGlobals.h"
- #include "DSUserProcs.h"
- #include "DSAppleEvents.h"
-
- #include "DropShell.h"
- #include "PDUtilities.h"
- #include "PDDialogs.h"
- #include "TasksAndErrors.h"
-
-
-
- Boolean gDone, gOApped, gHasAppleEvents, gWasEvent;
- EventRecord gEvent;
- MenuHandle gAppleMenu, gFileMenu;
-
- #ifdef MPW
- extern void _DataInit();
- #endif
-
-
- extern void DoFileMenu(short itemID);
-
-
- #pragma segment Initialize
- void InitToolbox (void)
- {
-
- #ifdef MPW
- UnloadSeg ((Ptr) _DataInit );
- #endif
-
- InitGraf ( &qd.thePort );
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (NULL); // use of ResumeProcs no longer approved by Apple
- InitCursor ();
- FlushEvents ( everyEvent, 0 );
-
- // how about some memory fun! Two should be enough!
- MoreMasters ();
- MoreMasters ();
-
- MaxApplZone();
- }
-
- /*
- Let's setup those global variables that the DropShell uses.
-
- If you add any globals for your own use,
- init them in the InitUserGlobals routine in DSUserProcs.c
- */
- #pragma segment Initialize
- Boolean InitGlobals (void)
- {
- long aLong;
-
- gDone = false;
- gOApped = false; // probably not since users are supposed to DROP things!
- gHasAppleEvents = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
-
- return(InitUserGlobals()); // call the user proc
- }
-
- /*
- Again, nothing fancy. Just setting up the menus.
-
- If you add any menus to your DropBox - insert them here!
- */
- #pragma segment Initialize
- void SetUpMenus (void) {
-
- gAppleMenu = GetMenu ( kAppleNum );
- AddResMenu ( gAppleMenu, 'DRVR' );
- InsertMenu ( gAppleMenu, 0 );
-
- gFileMenu = GetMenu ( kFileNum );
- InsertMenu ( gFileMenu, 0 );
- DrawMenuBar ();
- }
-
-
- /* --------------- Standard Event Handling routines ---------------------- */
- #pragma segment Main
- void ShowAbout () {
- (void) Alert ( 128, NULL );
- }
-
-
- #pragma segment Main
- void DoMenu ( long retVal ) {
- short menuID, itemID;
- Str255 itemStr;
-
- menuID = HiWord ( retVal );
- itemID = LoWord ( retVal );
-
- switch ( menuID ) {
- case kAppleNum:
- if ( itemID == 1 )
- {
- ShowAbout (); /* Show the about box */
- }
- else
- {
- GetItem(GetMHandle(kAppleNum), itemID, itemStr);
- OpenDeskAcc(itemStr);
- }
- break;
-
- case kFileNum:
- DoFileMenu(itemID);
- break;
-
- default:
- break;
-
- }
- HiliteMenu(0); // turn it off!
- }
-
-
- #pragma segment Main
- void DoMouseDown ( EventRecord *curEvent ) {
- WindowPtr whichWindow;
- short whichPart;
-
- whichPart = FindWindow ( curEvent->where, &whichWindow );
- switch ( whichPart ) {
- case inMenuBar:
- DoMenu ( MenuSelect ( curEvent->where ));
- break;
-
- case inSysWindow:
- SystemClick ( curEvent, whichWindow );
- break;
-
- case inDrag:
- {
- Rect boundsRect = (*GetGrayRgn())->rgnBBox;
- DragWindow ( whichWindow, curEvent->where, &boundsRect );
- }
- break;
- }
- }
-
-
- #pragma segment Main
- void DoKeyDown ( EventRecord *curEvent ) {
- if ( curEvent->modifiers & cmdKey )
- DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
- }
-
-
- #pragma segment Main
- static Boolean IsCommandKey(EventRecord *event) {
- return (event->what == keyDown) && ((event->modifiers & cmdKey) != 0);
- }
-
- #pragma segment Main
- void main ( )
- {
- InitToolbox ();
- if ( !InitGlobals () ) return;
- if ( !gHasAppleEvents ) {
- ErrorAlert ( kErrStringID, kCantRunErr, 0 );
- DisposeUserGlobals(); // call the userproc to clean itself up
- return;
- }
- InitAEVTStuff ();
- SetUpMenus ();
-
- while ( !gDone ) {
- gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
- if ( !gWasEvent )
- {
- Str255 s;
- GetIndString(s, kProjectDragStrings, kIdleStatus);
- SetStatusMessage(s);
- continue;
- }
-
- /* handle dialog updating */
- if (!IsCommandKey(&gEvent) && IsDialogEvent(&gEvent)) {
- DialogPtr dialog;
- short itemHit;
-
- DialogSelect(&gEvent, &dialog, &itemHit);
- continue;
- }
-
- switch ( gEvent.what ) {
- case kHighLevelEvent:
- DoHighLevelEvent ( &gEvent );
- break;
-
- case mouseDown:
- DoMouseDown ( &gEvent );
- break;
-
- case keyDown:
- case autoKey:
- DoKeyDown ( &gEvent );
- break;
-
- case diskEvt:
- if (HiWord(gEvent.message)) {
- Point diskInitPt;
-
- diskInitPt.v = diskInitPt.h = 100;
- DILoad();
- DIBadMount(diskInitPt, gEvent.message);
- DIUnload();
- }
- break;
- }
-
- PopAllTasks();
- }
-
- DisposeUserGlobals(); // call the userproc to clean itself up
- }
-